package com.atguigu.spzx.manage.controller;

import com.atguigu.spzx.manage.service.BannerService;
import com.atguigu.spzx.model.entity.system.Banner;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/admin/system/banner")
@Slf4j
@Tag(name = "轮播图管理接口")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    @Operation(summary = "轮播图查询")
    @GetMapping(value = "/getBanner")
    public Result getBanner(){
        List<Banner> bannerList=bannerService.getBanner();
        return Result.build(bannerList,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "添加轮播图")
    @PostMapping(value = "/saveBanner")
    public Result saveBanner(@RequestBody Banner banner) {
        log.info("添加的角色:{}",banner);
        bannerService.saveBanner(banner) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }


    @Operation(summary = "修改轮播图")
    @PostMapping(value = "/updateBanner")
    public Result updateBanner(@RequestBody Banner banner) {
        log.info("修改的banner:{}",banner);
        bannerService.updateBanner(banner) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "删除轮播图")
    @DeleteMapping(value = "/deleteById/{bannerId}")
    //userid
    public Result deleteById(@PathVariable(value = "bannerId") Long id) {
        bannerService.deleteById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
}
